package com.hyc.atomic;

import com.hyc.entity.Person;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class AtomicReferenceFieldUpdaterDemo {
    public static void main(String[] args) {
        AtomicReferenceFieldUpdater<Person, String> updater = AtomicReferenceFieldUpdater.newUpdater(Person.class, String.class, "name");
        Person p = new Person();
        p.name = "aaa";
        System.out.println(updater.compareAndSet(p, "aaa", "bbb"));
        System.out.println(p.name);
        System.out.println(updater.getAndSet(p, "ccc"));
        System.out.println(p.name);
    }
}
